package com.vteba.tx.jdbc.sequence;


/**
 * 通过单个表模拟多个sequence，性能会低。<br>
 * 1、sequence名字栏位默认name。<br>
 * 2、sequence值的栏位默认value。<br>
 * @author 尹雷 
 * @since 2012-12-1
 */
public class SingleTableGenerator extends AbstractKeyGenerator implements KeyGenerator {
    private String valueColumn = "value";// sequence值的栏位名
    private String nameColumn = "name";// sequence名的栏位名
    private String sequenceName = "sequence";// 模拟sequence名字
    private SingleMaxValueIncrementer singleMaxValueIncrementer;

    public String getValueColumn() {
        return valueColumn;
    }

    public void setValueColumn(String valueColumn) {
        this.valueColumn = valueColumn;
    }

    public String getNameColumn() {
        return nameColumn;
    }

    public void setNameColumn(String nameColumn) {
        this.nameColumn = nameColumn;
    }

    public String getSequenceName() {
        return sequenceName;
    }

    public void setSequenceName(String sequenceName) {
        this.sequenceName = sequenceName;
    }

	@Override
	public void setDataFieldIncrementer() {
		setSequenceName(sequenceName);
        singleMaxValueIncrementer = new SingleMaxValueIncrementer(getDataSource(), 
        		sequenceName, valueColumn, nameColumn, sequenceName);
        singleMaxValueIncrementer.afterPropertiesSet();
		this.dataFieldIncrementer = singleMaxValueIncrementer;
	}

}
